<template>
  <div>
    <div>
      <h1>{{ task_list.title }}</h1>
      <hr />
    </div>
    <div>
      {{ task_list.content }}
      <hr />
    </div>
    <van-button type="default" @click="upd_record">提交</van-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      task_id: this.$route.query.task_id,
      task_list: {},
      user_id: localStorage.getItem("id"),
    };
  },
  mounted() {
    this.task_show();
  },
  methods: {
    task_show: function () {
      this.myaxios(this.host + "study/task/" + this.task_id + "/", "get", {
        user_id: this.user_id,
      }).then((data) => {
        console.log(data);
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.task_list = data.data;
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
    upd_record: function () {
      this.myaxios(this.host + "study/record/", "put", {
        user_id: this.user_id,
        title: this.task_list.title,
      }).then((data) => {
        console.log(data);
        if (data.code == 200) {
          this.$toast.success(data.msg);
          this.$router.push({
            path: "/menu/task",
          });
        } else {
          this.$toast.fail(data.msg);
        }
      });
    },
  },
};
</script>

<style>
</style>